DevForce Help Reference
InvokeServerMethod(String,String,Object[]) Method
Example 


Assembly-qualified type name such as 'MyNamespace.Services, MyAssembly'
Name of method to be invoked
Arguments to be passed to method
Invokes the specified static method for execution on the server.
Syntax
'Declaration
 
Public Overloads Function InvokeServerMethod( _
   ByVal fullTypeName As String, _
   ByVal methodName As String, _
   ByVal ParamArray userArgs() As Object _
) As Object
'Usage
 
Dim instance As EntityManager
Dim fullTypeName As String
Dim methodName As String
Dim userArgs() As Object
Dim value As Object
 
value = instance.InvokeServerMethod(fullTypeName, methodName, userArgs)
public object InvokeServerMethod( 
   string fullTypeName,
   string methodName,
   params object[] userArgs
)

Parameters

fullTypeName
Assembly-qualified type name such as 'MyNamespace.Services, MyAssembly'
methodName
Name of method to be invoked
userArgs
Arguments to be passed to method
Exceptions
ExceptionDescription
System.ArgumentExceptionType name must be an assembly qualified type name.
System.Security.SecurityExceptionThrown if the method is not marked with the AllowRpcAttribute
PersistenceSecurityExceptionThrown if the server method is decorated with an AuthorizationAttribute and the user is not authorized to execute the method.
Remarks
The method called must be marked with the AllowRpcAttribute and correspond to the ServerMethodDelegate signature.

InvokeServerMethod enables a client-side caller to invoke an arbitrary static method on the server. The method can return any kind of serializable object.

This feature is only available in certain editions of DevForce.
Example
// Sample showing invocation of server method
EntityManager mgr = new DomainModelEntityManager();
int orderId = 10250;
bool mailSent = (bool) mgr.InvokeServerMethod(Order.EmailOrderInfo, orderId);

// sample method defined in Order class
public class Order {
//...
  // ServerMethodDelegate method, called from client
  [AllowRpc]
  public static Object EmailOrderInfo(IPrincipal pPrincipal, EntityManager pPm, params Object[] pArgs) {
    int orderId = Convert.ToInt32(pArgs[0]);

    // build and send an email message 
    string from = "sales@mycompany.com";
    string to = "customer@yourcompany.com";
    System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage(from, to);
    msg.Subject = "Order Information";
    msg.Body = string.Format("Order id = {0} has been shipped", orderId);

    System.Net.Mail.SmtpClient mailClient = new System.Net.Mail.SmtpClient("localhost");
    try {
      mailClient.Send(msg);
    } catch (Exception e) {
      TraceFns.WriteLine(e.Message);
      return false;
    }
    return true;
 }
}
' Sample showing invocation of server method
Dim mgr As EntityManager As New DomainModelEntityManager()
Dim orderId As Integer = 10250
Dim mailSent As Boolean = CBool(mgr.InvokeServerMethod(Order.EmailOrderInfo, orderId))

' sample method defined in Order class
Public Class Order 
'...
  Public Shared<AllowRpc()>  _
  Function EmailOrderInfo(pPrincipal As IPrincipal, pManager As EntityManager, ParamArray pArgs() As [Object]) As [Object]
    Dim orderId As Integer = Convert.ToInt32(pArgs(0))
   
    ' build and send an email message 
    Dim from As String = "sales@mycompany.com"
    Dim [to] As String = "customer@yourcompany.com"
    Dim msg As New System.Net.Mail.MailMessage(from, [to])
   
    msg.Subject = "Order Information"
    msg.Body = String.Format("Order id = {0} has been shipped", orderId)
   
    Dim client As New System.Net.Mail.SmtpClient("localhost")
    Try
      client.Send(msg)
    Catch e As Exception
      TraceFns.WriteLine(e.Message)
      Return False
   End Try
   Return True
 End Function 
End Class
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

EntityManager Class
EntityManager Members
Overload List

Send Feedback